package com.xgst.bmg.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xgst.bmg.entity.CmsPut;
import com.xgst.bmg.service.AsyncSercive;
import com.xgst.bmg.sse.service.SSEService;
import com.xgst.bmg.utils.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.bytedeco.javacpp.avcodec;
import org.bytedeco.javacpp.avutil;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @description: 前置jar包SSE控制器
 * @author: 文东旭
 * @createDate: 2021/01/19
 * @version: v1.0
 * @instruction: 个人信息：android_personal_information
 * 好差评：android_good_bad_review
 * 离席提示：android_stop_service
 * 取消离席&个人信息：android_start_service
 * 同屏展示：android_screen_sharing
 * 满意度：android_satisfaction
 */
@RestController
@EnableScheduling
@RequestMapping("/sseService")
public class SSEController {

	private static final Logger log = LoggerFactory.getLogger(SSEController.class);
	private static SseEmitter emitter = null;
	private static ArrayList<String> gaoPeiYiImgJson = new ArrayList();//保存高配仪图片接口上传成功返回的JSON字符串
	private static ArrayList<String> dzzzImgJson = new ArrayList();//保存电子证照图片接口上传成功返回的JSON字符串
	private static ArrayList<String> dzzzImgBase64Json = new ArrayList();//保存获取到的电子证照图片的JSON字符串
	private static Charset charset = Charset.forName("UTF-8");
	private static boolean isget = false;
	private static JSONObject socialSecurityHallJson  = null;

	//启动停止
	private static boolean bl = false;

	//本地
	private String URL = "http://172.16.10.190:1091";
	private String RECEIVEURL = "http://172.16.10.190:1085";
	//10服务器
//	private String URL = "http://172.16.30.10:1091";
//	private String RECEIVEURL = "http://172.16.30.10:1085";
	//石景山社保大厅
//	private String URL = "http://172.25.92.145:1091";
//	private String RECEIVEURL = "http://172.25.92.145:1085";
	//服务器
//	private String URL = "";
//	private String RECEIVEURL = "";

	@Value("${ffmpeg.framerate}")
	private int FRAMERATE;

	@Value("${ffmpeg.gopsize}")
	private int GOPSIZE;

	@Value("${ffmpeg.videobitrate}")
	private int VIDEOBITRATE;

	@Autowired
	private AsyncSercive asyncSercive;
	@Autowired
	private SSEService sseService;


	/**
	 * @author: 文东旭
	 * @createDate: 2021/01/25
	 * @description: pad直接创建jar包SSE接口
	 * @return
	 * @throws IOException
	 */
	@ApiOperation("pad直接创建jar包SSE接口")
	@ApiImplicitParams({})
	@GetMapping("/docking")
	public SseEmitter docking() {
		emitter = sseService.start("1");
		JSONObject returnJson = new JSONObject();
		returnJson.put("returnType", "docking_success");
		try {
			emitter.send(SseEmitter.event().reconnectTime(1).data(returnJson.toJSONString()));
			log.info("docking success");
		} catch (IOException e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
		}
		return emitter;
	}

	public static void sseSend(String content) {
		try {
			emitter.send(SseEmitter.event().reconnectTime(1).data(content));
			log.info("send success:"+content);
		} catch (IOException e) {
			log.info("send fail:"+content);
			e.printStackTrace();
			log.error(e.getMessage(),e);
		}
	}

	/**
	 * @param recvId 办件编号
	 * @author: 文东旭
	 * @createDate: 2021/01/22
	 * @description: 获取本机MAC地址接口(已弃用)
	 * @return
	 */
	@ApiOperation("获取本机MAC地址接口(已弃用)")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "recvId", value ="办件编号",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/getLocalMac")
	public String getLocalMac(String recvId) throws Exception {
		LocalInforUtils utils = new LocalInforUtils();
		String mac = utils.getLocalMac();
		mac = EncrypUtil.encode(mac);
		HttpClientUtil.getInstance().doGet(URL + "/sseController/controllerUserEvaluationPC?recvId="+recvId+"&macOrRandomCode="+mac);
		log.info("getLocalMac success:"+recvId+" "+mac);
		return mac;
	}

	/**
	 * @param recvId 办件编号
	 * @param taskId 事项ID
	 * @param taskName 事项名称
	 * @param isConverge 是否汇聚（0=汇聚，9=不汇聚）
	 * @author: 文东旭
	 * @createDate: 2021/01/22
	 * @description: 好差评-PC触发接口，推送给pad
	 * @return
	 */
	@ApiOperation("好差评-PC触发接口，推送给pad")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "recvId", value ="办件编号",dataType = "String", required = true),
			@ApiImplicitParam(name = "taskId", value ="事项ID",dataType = "String", required = true),
			@ApiImplicitParam(name = "taskName", value ="事项名称",dataType = "String", required = true),
			@ApiImplicitParam(name = "isConverge", value ="是否汇聚（0=汇聚，9=不汇聚）",dataType = "String", required = false)
	})
	@ResponseBody
	@GetMapping("/userEvaluationPC")
	public String userEvaluationPC(String recvId, String taskId, String taskName, String isConverge, HttpServletResponse response) {
		//设置响应头
		log.info("userEvaluationPC");
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		json.put("returnType", "android_good_bad_review");
		try {
			JSONObject js = new JSONObject();
			js.put("recvId", recvId);
			js.put("taskId", taskId);
			js.put("taskName", taskName);
			json.put("bmgTaskRecv", js);
			if(StringUtils.isNotBlank(isConverge)){
				json.put("isConverge", isConverge);
			}
			JSONObject evaluationIndexInfoJson = JSONObject.parseObject(HttpClientUtil.getInstance().doGet(URL + "/bmgTaskRecvAppraise/getEvaluationIndexInfo"));
			if(evaluationIndexInfoJson.getInteger("code") == 200){
				json.put("evaluationIndexInfo", evaluationIndexInfoJson.get("EvaluationIndexInfo"));
			}else{
				new Exception();
			}
			sseSend(json.toJSONString());
			log.info("userEvaluationPC success");
			returnJson.put("code", 200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @param jsonParams 评价数据
	 * @author: 文东旭
	 * @createDate: 2021/01/22
	 * @description: 好差评-pad评价提交接口
	 * @return
	 */
	@ApiOperation("好差评-pad评价提交接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "jsonParams", value ="评价数据",dataType = "String", required = true)
	})
	@ResponseBody
	@PostMapping("/userEvaluationPad")
	public String userEvaluationPad(@RequestBody Map jsonParams, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		try {
			JSONObject renturnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPostJson(URL + "/bmgTaskRecvAppraise/saveBmgTaskRecvAppraise", jsonParams));
			returnJson.put("code", renturnJson.getInteger("code"));
			log.info("userEvaluationPad success");
			log.info("renturnJson   "+renturnJson.toJSONString());
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/01/28
	 * @description: 互动双屏-请您稍后
	 * @return
	 */
	@ApiOperation("互动双屏-请您稍后")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/pleaseWait")
	public String pleaseWait(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		json.put("returnType", "android_please_wait");
		try {
			sseSend(json.toJSONString());
			returnJson.put("code", 200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/01/28
	 * @description: 互动双屏-离席提示
	 * @return
	 */
	@ApiOperation("互动双屏-离席提示")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/departure")
	public String departure(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		json.put("returnType", "android_stop_service");
		try {
			sseSend(json.toJSONString());
			returnJson.put("code", 200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @param userId 用户ID
	 * @author: 文东旭
	 * @createDate: 2021/01/28
	 * @description: 互动双屏-取消离席&个人信息
	 * @return
	 */
	@ApiOperation("互动双屏-取消离席&个人信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userId", value ="用户ID",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/cancelDepartureAndPersonInfo")
	public String cancelDepartureAndPersonInfo(String userId, HttpServletRequest request, HttpServletResponse response) {
		//获取请求页面的域名
		String origin = request.getHeader("Origin");
		log.info("Origin-- "+origin);
		//正式服务器
		URL = origin+"/screen";
		RECEIVEURL = origin+"/api";
		//10服务器
//		URL = origin.split(":")[0]+":"+origin.split(":")[1]+":1091";
//		RECEIVEURL = origin.split(":")[0]+":"+origin.split(":")[1]+":1085";
		log.info("URL-- "+URL);
		log.info("RECEIVEURL-- "+RECEIVEURL);
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		json.put("returnType", "android_start_service");
		try {
			JSONObject confJson = LocalInforUtils.getConfFile();
			log.info("--confJson   "+confJson.toJSONString());
			String winIp = confJson.getString("winIp");
			JSONObject jsonParams = new JSONObject();
			jsonParams.put("userId",userId);
			jsonParams.put("winIp",winIp);
			log.info("--jsonParams   "+jsonParams.toJSONString());
			String renturnStr = HttpClientUtil.getInstance().doPostJson(URL + "/bmgTaskRecvAppraise/getUserByUserIdAndIp", jsonParams);
			System.out.println("--renturnStr "+renturnStr);
			JSONObject renturnJson = JSONObject.parseObject(renturnStr);
			log.info("--renturnJson "+renturnJson.toJSONString());
			String userDownloadFilePath = "http://" + renturnJson.getString("userDownloadFilePath");
			log.info("--userDownloadFilePath "+userDownloadFilePath);
			String userFileType = renturnJson.getString("userFileType");
			String userFileName = renturnJson.getString("pictureFileId");
			log.info("--path "+"C:/file/"+userFileName+"."+userFileType);
			File userFile = new File("C:/file/"+userFileName+"."+userFileType);
			String photoUrl = "";
			if(userFile.exists()){
				log.info("--exists ");
				//拼接本地服务静态文件远程访问地址
				photoUrl = "http://"+winIp+"/myPcServer/"+userFileName+"."+userFileType;
			}else{
				log.info("--no exists ");
				photoUrl = downloadFileAndGenerateLocalFileUrl(userDownloadFilePath,userFileType,userFileName);
				log.info("--1 ");
			}
			renturnJson.put("photoUrl",photoUrl);
			JSONObject winMngJson = renturnJson.getJSONObject("winMng");
			log.info("--2 ");
			String winDownloadFilePath = "http://" + winMngJson.getString("winDownloadFilePath");
			log.info("--3 ");
			String winFileType = winMngJson.getString("winFileType");

			String winFileName = winMngJson.getString("winHonorFileId");
			File winFile = new File("C:/file/"+winFileName+"."+winFileType);
			log.info("--4 ");
			String winHonorFileUrl = "";
			if(winFile.exists()){
				//拼接本地服务静态文件远程访问地址
				winHonorFileUrl = "http://"+winIp+"/myPcServer/"+winFileName+"."+winFileType;
				log.info("--5 ");
			}else{
				winHonorFileUrl = downloadFileAndGenerateLocalFileUrl(winDownloadFilePath,winFileType,winFileName);
				log.info("--6 ");
			}

			log.info("--winHonorFileUrl "+winHonorFileUrl);
			winMngJson.put("winHonorFileUrl",winHonorFileUrl);
			renturnJson.put("winMng",winMngJson);
			if ("200".equals(renturnJson.getString("code"))){
				log.info("--7 ");
				json.put("user",renturnJson);
				sseSend(json.toJSONString());
				returnJson.put("code", 200);
				return returnJson.toJSONString();
			}else{
				log.info("--8 ");
				return returnJson.toJSONString();
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/01/22
	 * @description: 互动双屏-同屏展示
	 * @return
	 */
	@ApiOperation("互动双屏-同屏展示")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/sameScreenDisplay")
	public String sameScreenDisplay(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		json.put("returnType", "android_screen_sharing");
		try {
			sseSend(json.toJSONString());
			returnJson.put("code", 200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/01/22
	 * @description: 互动双屏-满意度
	 * @return
	 */
	@ApiOperation("互动双屏-满意度")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/satisfaction")
	public String satisfaction(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		json.put("returnType", "android_satisfaction");
		try {
			sseSend(json.toJSONString());
			returnJson.put("code", 200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/01/29
	 * @description: 互动双屏-分享屏幕（已废弃）
	 * @return
	 */
	/*@ApiOperation("互动双屏-分享屏幕（已废弃）")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/startCapture")
	public void startCapture(){
		asyncSercive.setBl(true);
		if(emitter!=null){
			asyncSercive.setEmitter(emitter);
			asyncSercive.startBase64();
			asyncSercive.startCapture();
			asyncSercive.startEmitter();
		}else{
			log.info("客户端未连接");
		}
	}*/

	/**
	 * @author: 文东旭
	 * @createDate: 2021/01/29
	 * @description: 互动双屏-停止分享屏幕（已废弃）
	 * @return
	 */
	/*@ApiOperation("互动双屏-停止分享屏幕（已废弃）")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/stopCapture")
	public void stopCapture(){
		asyncSercive.setBl(false);
	}*/

	/**
	 * @author: 文东旭
	 * @createDate: 2021/03/02
	 * @description: 互动双屏-分享屏幕（推流方式）
	 * @return
	 */
	@ApiOperation("互动双屏-分享屏幕（推流方式）")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/startCapturePushStream")
	public String startCapturePushStream(HttpServletResponse response) throws IOException {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		JSONObject jsonan = new JSONObject();
		JSONObject confJson = LocalInforUtils.getConfFile();
		String winIp = confJson.getString("winIp");
		String rtmpUrl = "rtmp://"+winIp+"/live/shareScreen";
		bl = true;
		new Thread(()-> {
			try {
				Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
				Robot robot = new Robot();
				Rectangle screenRect = new Rectangle(screenSize);
				BufferedImage bufferedImageRGB = null;
				BufferedImage bufferedImageYUV = new BufferedImage(screenSize.width, screenSize.height, BufferedImage.TYPE_3BYTE_BGR);
				BufferedImage cursor= ImageIO.read(new File("C:/file/cursor.png"));
				Point p= null;
				Graphics g = null;
				Java2DFrameConverter java2dConverter = new Java2DFrameConverter();
				FFmpegFrameRecorder recorder = FFmpegFrameRecorder.createDefault("rtmp://"+winIp+":1935/live/shareScreen",screenSize.width,screenSize.height);
				recorder.setVideoCodec(avcodec.AV_CODEC_ID_FLV1);
				recorder.setFormat("flv");
				recorder.setFrameRate(FRAMERATE);
				recorder.setGopSize(GOPSIZE);
				recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
				recorder.setVideoBitrate(VIDEOBITRATE);
				recorder.start();
				while(bl){
					bufferedImageRGB = robot.createScreenCapture(screenRect);
					p= MouseInfo.getPointerInfo().getLocation();
					bufferedImageRGB.createGraphics().drawImage(cursor, p.x, p.y, null);
					g = bufferedImageYUV.getGraphics();
					g.drawImage(bufferedImageRGB, 0, 0, null);
					g.dispose();
					recorder.record(java2dConverter.convert(bufferedImageYUV));
				}
				recorder.stop();
				recorder.release();
			}catch (Exception e){
				e.printStackTrace();
				log.error(e.getMessage(),e);
			}
		}).start();
		jsonan.put("returnType", "android_pull_stream_start");
		jsonan.put("rtmpUrl", rtmpUrl);
		sseSend(jsonan.toJSONString());
		returnJson.put("code",200);
		return returnJson.toJSONString();
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/03/02
	 * @description: 互动双屏-停止分享屏幕（推流方式）
	 * @return
	 */
	@ApiOperation("互动双屏-停止分享屏幕（推流方式）")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/stopCapturePushStream")
	public String stopCapturePushStream(HttpServletResponse response){
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		bl = false;
		JSONObject jsonan = new JSONObject();
		jsonan.put("returnType", "android_pull_stream_stop");
		sseSend(jsonan.toJSONString());
		JSONObject returnJson = new JSONObject();
		returnJson.put("code",200);
		return returnJson.toJSONString();
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/02/03
	 * @description: 前端获取当前系统使用的高配仪类型标识，独立高配仪: gaoPeiYiType=duligaopeiyi, 双屏高配仪: gaoPeiYiType=shuangpinggaopeiyi
	 * @return
	 */
	@ApiOperation("前端获取当前系统使用的高配仪类型标识，独立高配仪: gaoPeiYiType=duligaopeiyi, 双屏高配仪: gaoPeiYiType=shuangpinggaopeiyi")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/getGaoPeiYiType")
	public String getGaoPeiYiType(HttpServletResponse response){
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject retJson = new JSONObject();
		try {
			JSONObject confJson = LocalInforUtils.getConfFile();
			String gaoPeiYiType = confJson.getString("gaoPeiYiType");
			retJson.put("code",200);
			retJson.put("gaoPeiYiType",gaoPeiYiType);
		} catch (IOException e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			retJson.put("code",201);
		}
		return retJson.toJSONString();
	}

	/**
	 * @param file 需要上传的文件
	 * @author: 文东旭
	 * @createDate: 2021/02/03
	 * @description: android双屏评价器自带高配仪上传文件
	 * @return
	 */
	@ApiOperation("android双屏评价器自带高配仪上传文件")
	@ApiImplicitParams({})
	@ResponseBody
	@PostMapping("/uploadFiles")
	public String uploadFiles(@RequestParam("file") MultipartFile file,HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		try {
			if (file.isEmpty()) {
				return "上传失败，请选择文件";
			}
			String fileName = file.getOriginalFilename();
			String filePath = "C:/file/";
			File dest = new File(filePath + fileName);
			//保存文件到本地文件夹
			file.transferTo(dest);
			log.info("本地服务接收文件成功");
			String path = filePath+fileName;
			String userId = UUID.randomUUID().toString().replace("-","");
			//上传文件
			String fileStrMsg = HttpClientUtil.getInstance(charset).doUpload(URL+"/bmgTaskRecvAppraise/gaoPeiYiUploadFiles?userId="+userId, "file", path);
			//删除临时文件
			File myDelFile = new File(path);
			myDelFile.delete();
			//存入List等待综窗前端轮询读取数据
			gaoPeiYiImgJson.add(fileStrMsg);
			returnJson.put("code",200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			returnJson.put("code",201);
			return returnJson.toJSONString();
		}
	}
	/**
	 * @author: 文东旭
	 * @createDate: 2021/02/03
	 * @description: 综窗前端轮询读取高配仪上传的文件数据
	 * @return
	 */
	@ApiOperation("综窗前端轮询读取高配仪上传的文件数据")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/readGaoPeiYiImg")
	public String readGaoPeiYiImg(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		try {
			//读取List中的返回信息
			String fileStrMsg = gaoPeiYiImgJson.get(0);
			//清空List
			gaoPeiYiImgJson.clear();
			return fileStrMsg;
		} catch (Exception e) {
			returnJson.put("code",201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/02/06
	 * @description: 互动双屏-电子证照-取消人脸扫描
	 * @return
	 */
	@ApiOperation("互动双屏-电子证照-取消人脸扫描")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/faceScanCancel")
	public String faceScanCancel(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		try {
			json.put("returnType", "android_face_scan_cancel");
			sseSend(json.toJSONString());
			returnJson.put("code", 200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}
	/**
	 * @param file 带水印的电子证照图片
	 * @author: 文东旭
	 * @createDate: 2021/02/06
	 * @description: 互动双屏-电子证照-上传带水印电子证照图片
	 * @return
	 */
	@ApiOperation("互动双屏-电子证照-上传带水印电子证照图片")
	@ApiImplicitParams({})
	@ResponseBody
	@PostMapping("/upLoadDzzzImg")
	public String upLoadDzzzImg(@RequestParam("file") MultipartFile file,HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		try {
			log.info("----uploadFile");
			if (file.isEmpty()) {
				return "上传失败，请选择文件";
			}
			String fileName = file.getOriginalFilename();
			String filePath = "C:/file/";
			File dest = new File(filePath + fileName);
			//保存文件到本地文件夹
			file.transferTo(dest);
			log.info("本地服务接收文件成功");
			String path = filePath+fileName;
			String userId = UUID.randomUUID().toString().replace("-","");
			log.info(RECEIVEURL+"/acceptFile/uploadFile?userId="+userId);
			//上传文件
			String fileStrMsg = HttpClientUtil.getInstance(charset).doUpload(RECEIVEURL+"/acceptFile/uploadFile?userId="+userId, "file", path);
			log.info("fileStrMsg"+fileStrMsg);
			//删除临时文件
			File myDelFile = new File(path);
			myDelFile.delete();
			//存入List等待综窗前端轮询读取数据
			dzzzImgJson.add(fileStrMsg);
			returnJson.put("code",200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code",201);
			return returnJson.toJSONString();
		}
	}
	/**
	 * @author: 文东旭
	 * @createDate: 2021/02/03
	 * @description: 综窗前端轮询读取电子证照上传的文件数据
	 * @return
	 */
	@ApiOperation("综窗前端轮询读取电子证照上传的文件数据")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/readDzzzImg")
	public String readDzzzImg(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		try {
			//读取List中的返回信息
			String fileStrMsg = dzzzImgJson.get(0);
			//清空List
			dzzzImgJson.clear();
			return fileStrMsg;
		} catch (Exception e) {
			returnJson.put("code",201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @param beforInstruction 上一个指令
	 * @author: 文东旭
	 * @createDate: 2021/03/06
	 * @description: android通知本地服务执行下一步指令
	 * @return
	 */
	@ApiOperation("android通知本地服务执行下一步指令")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "beforInstruction", value ="上一个指令",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/nextInstruction")
	public String nextInstruction(String beforInstruction, HttpServletResponse response){
		log.info("--nextInstruction");
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		if("android_face_scan".equals(beforInstruction)){
			//发送电子证照（非门头沟区）
			log.info("--android_face_scan");
			new Thread(()-> {
				while (true){
					if(isget){
						log.info("--sseSenddzzzImgBase64Json");
						sseSend(dzzzImgBase64Json.get(0));
						dzzzImgBase64Json.clear();
						break;
					}
				}
			}).start();
		}else if("android_gaopeiyi".equals(beforInstruction)){
			//调取高配仪（非门头沟区）
			log.info("--android_gaopeiyi");
			new Thread(()-> {
				while (true){
					if(isget){
						log.info("--sseSenddzzzImgBase64Json");
						sseSend(dzzzImgBase64Json.get(0));
						dzzzImgBase64Json.clear();
						break;
					}
				}
			}).start();
		}
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("code", 200);
		return jsonObject.toJSONString();
	}


	/**
	 * @param areaId 区域ID
	 * @param pageNum 页数
	 * @param pageSize 每页条数
	 * @param taskLevel 事项等级
	 * @param taskName 事项名称
	 * @param unitId 单位ID
	 * @author: 文东旭
	 * @createDate: 2021/03/15
	 * @description: 根据所属区id查询首页委办局事项
	 * @return
	 */
	@ApiOperation("根据所属区id查询首页委办局事项")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNum", value ="页数",dataType = "String", required = true),
			@ApiImplicitParam(name = "pageSize", value ="每页条数",dataType = "String", required = true),
			@ApiImplicitParam(name = "areaId", value ="区域ID",dataType = "String", required = true),
			@ApiImplicitParam(name = "taskLevel", value ="事项等级",dataType = "String", required = true),
			@ApiImplicitParam(name = "unitId", value ="单位ID",dataType = "String", required = true),
			@ApiImplicitParam(name = "taskName", value ="事项名称",dataType = "String", required = false)
	})
	@ResponseBody
	@GetMapping("/findAllTask")
	public String findAllTask(Integer pageNum,Integer pageSize,String areaId,Integer taskLevel,String unitId,String taskName, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		JSONObject jsonParams = new JSONObject();
		jsonParams.put("pageNum",pageNum);
		jsonParams.put("pageSize",pageSize);
		jsonParams.put("areaId",areaId);
		jsonParams.put("taskLevel",taskLevel);
		jsonParams.put("unitId",unitId);
		jsonParams.put("taskName",taskName);
		try {
			returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPost(URL + "/bmgTaskRecvAppraise/findAllTask", jsonParams));
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("code", 201);
			return jsonObject.toJSONString();
		}
	}


	/**
	 * @param taskId 事项ID
	 * @author: 文东旭
	 * @createDate: 2021/03/15
	 * @description: 根据taskId查询事项办事指南
	 * @return
	 */
	@ApiOperation("根据taskId查询事项办事指南")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "taskId", value ="事项ID",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/findGuideByTaskId")
	public String findGuideByTaskId(String taskId, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		JSONObject jsonParams = new JSONObject();
		jsonParams.put("taskId",taskId);
		try {
			returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPost(URL + "/bmgTaskRecvAppraise/findGuideByTaskId", jsonParams));
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("code", 201);
			return jsonObject.toJSONString();
		}
	}


	/**
	 * @param pageNum 页数
	 * @param pageSize 每页条数
	 * @param terminalCode 终端编号
	 * @author: 文东旭
	 * @createDate: 2021/03/15
	 * @description: Pad根据平台ID查询政策解读列表
	 * @return
	 */
	@ApiOperation("Pad根据平台ID查询政策解读列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNum", value ="页数",dataType = "String", required = true),
			@ApiImplicitParam(name = "pageSize", value ="每页条数",dataType = "String", required = true),
			@ApiImplicitParam(name = "terminalCode", value ="终端编号",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/findCmsArticleVideoPictureListByTerminalCode")
	public String findCmsArticleVideoPictureListByTerminalCode(Integer pageNum, Integer pageSize,String terminalCode, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		JSONObject jsonParams = new JSONObject();
		jsonParams.put("pageNum",pageNum);
		jsonParams.put("pageSize",pageSize);
		jsonParams.put("terminalCode",terminalCode);
		try {
			JSONObject confJson = LocalInforUtils.getConfFile();
			String winIp = confJson.getString("winIp");
			returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPost(URL + "/bmgTaskRecvAppraise/findCmsArticleVideoPictureListByTerminalCode", jsonParams));
			JSONArray jsonArray = (JSONArray) returnJson.get("list");
			List<CmsPut> cmsPuts = JSONObject.parseArray(jsonArray.toJSONString(), CmsPut.class);
			for (int i = 0; i<cmsPuts.size(); i++) {
				if(cmsPuts.get(i).getCmsType() == 2){
					String coverFileIdFileRelativePath = cmsPuts.get(i).getCoverFileIdFileRelativePath();
					//base64编码重定向网址，防止整个接口出现两个"http://"报错
					cmsPuts.get(i).setCoverFileIdFileRelativePath("http://"+winIp+"/sseService/redirectToOrigin?fileType=3&originurl="+Base64Util.encode("http://"+coverFileIdFileRelativePath));
					String fileIdFileRelativePath = cmsPuts.get(i).getFileIdFileRelativePath();
					//base64编码重定向网址，防止整个接口出现两个"http://"报错
					cmsPuts.get(i).setFileIdFileRelativePath("http://"+winIp+"/sseService/redirectToOrigin?fileType=2&originurl="+Base64Util.encode("http://"+fileIdFileRelativePath));
				}else if(cmsPuts.get(i).getCmsType() == 3){
					String coverFileIdFileRelativePath = cmsPuts.get(i).getCoverFileIdFileRelativePath();
					//base64编码重定向网址，防止整个接口出现两个"http://"报错
					cmsPuts.get(i).setCoverFileIdFileRelativePath("http://"+winIp+"/sseService/redirectToOrigin?fileType=3&originurl="+Base64Util.encode("http://"+coverFileIdFileRelativePath));
				}
			}
			returnJson.put("list",cmsPuts);
			log.info(returnJson.toJSONString());
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("code", 201);
			return jsonObject.toJSONString();
		}
	}


	/**
	 * @param fileType 文件类型
	 * @param originurl 源网址
	 * @author: 文东旭
	 * @createDate: 2021/03/15
	 * @description: 根据文章ID查询获取CMS文章详情
	 * @return
	 */
	@ApiOperation("根据文章ID查询获取CMS文章详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "fileType", value ="文件类型",dataType = "String", required = true),
			@ApiImplicitParam(name = "originurl", value ="源网址",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/redirectToOrigin")
	public void redirectToOrigin(String fileType, String originurl, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		if("2".equals(fileType)){
			response.addHeader("Content-Type", "video/mp4");
		}else if("3".equals(fileType)){
			response.addHeader("Content-Type", "image/png");
		}
		//CMS原路径base64编码后通过get提交，这里base64解码后使用
		originurl = Base64Util.decode(originurl);
		log.info(originurl);
		try {
			java.net.URL url = new java.net.URL(originurl);
			URLConnection conn = url.openConnection();
			conn.setConnectTimeout(1000);
			conn.setReadTimeout(5000);
			conn.connect();
			InputStream inputStream = conn.getInputStream();
			IOUtils.copy(inputStream,response.getOutputStream());
			response.flushBuffer();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
		}
	}

	/**
	 * @param articleId 文章ID
	 * @author: 文东旭
	 * @createDate: 2021/03/15
	 * @description: 根据文章ID查询获取CMS文章详情
	 * @return
	 */
	@ApiOperation("根据文章ID查询获取CMS文章详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "articleId", value ="文章ID",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/findCmsArticleByArticleId")
	public String findCmsArticleByArticleId(String articleId, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		JSONObject jsonParams = new JSONObject();
		jsonParams.put("articleId",articleId);
		try {
			returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPost(URL + "/bmgTaskRecvAppraise/findCmsArticleByArticleId", jsonParams));
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("code", 201);
			return jsonObject.toJSONString();
		}
	}


	/**
	 * @author: 文东旭
	 * @createDate: 2021/03/23
	 * @description: 获取当前计算机IP
	 * @return
	 */
	@ApiOperation("获取当前计算机IP")
	@ApiImplicitParams({})
	@RequestMapping(value = "getLocalIp", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	public String getLocalIp(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		JSONObject confJson = null;
		try {
			confJson = LocalInforUtils.getConfFile();
			String winIp = confJson.getString("winIp");
			returnJson.put("ip", winIp);
			returnJson.put("code", 200);
			return returnJson.toJSONString();
		} catch (IOException e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/04/28
	 * @description: 安卓录入指纹指令
	 * @return
	 */
	@ApiOperation("安卓录入指纹指令")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/fingerprint")
	public String fingerprint(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		json.put("returnType", "android_fingerprint");
		try {
			sseSend(json.toJSONString());
			returnJson.put("code", 200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/04/28
	 * @description: 安卓录入签字指令
	 * @return
	 */
	@ApiOperation("安卓录入签字指令")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/signature")
	public String signature(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		json.put("returnType", "android_signature");
		try {
			sseSend(json.toJSONString());
			returnJson.put("code", 200);
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			return returnJson.toJSONString();
		}
	}



	/**
	 * @param taskName 事项名称
	 * @param department 部门名称
	 * @param telPhone 评价群众手机号
	 * @param userName 评价群众姓名
	 * @param certkeygov 评价群众证件号码
	 * @author: 文东旭
	 * @createDate: 2021/01/22
	 * @description: 好差评-(咨询场景下)PC触发接口发送评价指令给pad
	 * @return
	 */
	@ApiOperation("好差评-(咨询场景下)PC触发接口发送评价指令给pad")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "taskName", value ="事项名称",dataType = "String", required = true),
			@ApiImplicitParam(name = "department", value ="部门名称",dataType = "String", required = true),
			@ApiImplicitParam(name = "telPhone", value ="评价群众手机号",dataType = "String", required = true),
			@ApiImplicitParam(name = "userName", value ="评价群众姓名",dataType = "String", required = true),
			@ApiImplicitParam(name = "certkeygov", value ="评价群众证件号码",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/userEvaluationPCInChat")
	public String userEvaluationPCInChat(String taskName, String department, String telPhone, String userName, String certkeygov, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		json.put("returnType", "android_good_bad_review");
		try {
			JSONObject js = new JSONObject();
			js.put("taskName", taskName);
			js.put("department", department);
			js.put("telPhone", telPhone);
			js.put("userName", userName);
			js.put("certkeygov", certkeygov);
			//获取评价指标
			JSONObject evaluationIndexInfoJson = JSONObject.parseObject(HttpClientUtil.getInstance().doGet(URL + "/bmgTaskRecvAppraise/getEvaluationIndexInfo"));
			log.info("----evaluationIndexInfoJson "+evaluationIndexInfoJson.toJSONString());
			if(evaluationIndexInfoJson.getInteger("code") == 200){
				log.info("----EvaluationIndexInfo "+JSONObject.toJSONString(evaluationIndexInfoJson.getJSONObject("EvaluationIndexInfo")));
				js.put("evaluationIndexInfo", evaluationIndexInfoJson.get("EvaluationIndexInfo"));
			}else{
				new Exception();
			}
			json.put("bmgTaskRecvDouble", Base64Util.encode(js.toJSONString()));
			log.info("----json.toJSONString() "+json.toJSONString());
			sseSend(json.toJSONString());
			returnJson.put("code", 200);
			returnJson.put("msg", "评价成功");
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson.put("code", 201);
			returnJson.put("msg", e.getStackTrace());
			return returnJson.toJSONString();
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/01/29
	 * @description: 互动双屏-下载文件保存读取并转为Base64（已废弃）
	 * @return
	 */
	/*public static String downloadAndBase64(String downloadFilePath,String fileType, String fileName) throws Exception {
		log.info("1111");
		HttpClientUtil.getInstance().doDownload(downloadFilePath, "C:/file/"+fileName+"."+fileType);
		log.info("2222");
		InputStream userInputStream = null;
		String downloadFilePath1 = "C:/file/"+fileName+"."+fileType;
		File file = new File(downloadFilePath1);
		if (file.exists()) {
			userInputStream = new BufferedInputStream(new FileInputStream(file));
		}
		//转换为字节数组
		byte[] os = IOUtils.toByteArray(userInputStream);
		log.info("3333");
		//转换为base64
		String photoUrl = "data:image/"+fileType+";base64,"+ Base64.encodeBase64String(os);
		log.info("4444");
		return photoUrl;
	}*/

	/**
	 * @author: 文东旭
	 * @createDate: 2021/05/18
	 * @description: 互动双屏-下载文件保存读取并生成PC本地服务静态文件远程访问地址
	 * @return
	 */
	public static String downloadFileAndGenerateLocalFileUrl(String downloadFilePath,String fileType, String fileName) {
		JSONObject confJson = null;
		String winIp = "";
		try {
			HttpClientUtil.getInstance().doDownload(downloadFilePath, "C:/file/"+fileName+"."+fileType);
			confJson = LocalInforUtils.getConfFile();
			winIp = confJson.getString("winIp");
		}catch (Exception e){
			e.printStackTrace();
			log.error(e.getMessage(),e);
		}
		//拼接本地服务静态文件远程访问地址
		String photoUrl = "http://"+winIp+"/myPcServer/"+fileName+"."+fileType;
		return photoUrl;
	}

	/**
	 * @param path base64编码
	 * @param userId 用户ID
	 * @param callDzzz 是否调用电子证照('true'或'false')
	 * @param applicantIdNo 申请人证件号
	 * @param applicantName 申请人姓名
	 * @param applicantType 申请人类型
	 * @param licenseName 证照名称
	 * @param taskId 事项ID
	 * @param authCode 授权码
	 * @author: 文东旭
	 * @createDate: 2021/02/03
	 * @description: 独立高配仪上传文件/前端调取android双屏评价器自带高配仪
	 * @return
	 */
	@ApiOperation("独立高配仪上传文件/前端调取android双屏评价器自带高配仪")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "path", value ="图片所在路径(base64编码)",dataType = "String", required = true),
			@ApiImplicitParam(name = "userId", value ="用户ID",dataType = "String", required = true),
			@ApiImplicitParam(name = "callDzzz", value ="是否调用电子证照('true'或'false')",dataType = "String", required = true),
			@ApiImplicitParam(name = "applicantIdNo", value ="申请人证件号",dataType = "String", required = true),
			@ApiImplicitParam(name = "applicantName", value ="申请人姓名",dataType = "String", required = true),
			@ApiImplicitParam(name = "applicantType", value ="申请人类型",dataType = "String", required = true),
			@ApiImplicitParam(name = "licenseName", value ="证照名称",dataType = "String", required = true),
			@ApiImplicitParam(name = "taskId", value ="事项ID",dataType = "String", required = true),
			@ApiImplicitParam(name = "authCode", value ="授权码",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/gaoPeiYiUploadFiles")
	public String gaoPeiYiUploadFiles(String path,String userId,String callDzzz,String applicantIdNo, String applicantName, String applicantType, String licenseName, String taskId, String authCode, HttpServletResponse response){
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson1 = new JSONObject();
		try {
			JSONObject confJson = LocalInforUtils.getConfFile();
			String gaoPeiYiType = confJson.getString("gaoPeiYiType");
			if("duligaopeiyi".equals(gaoPeiYiType)){
				//独立高配仪上传文件
				String url = URL + "/bmgTaskRecvAppraise/gaoPeiYiUploadFiles?userId="+userId;
				//图片所在路径base64编码后通过get提交，这里base64解码后使用
				path = Base64Util.decode(path);
				String name = "file";
				String ret = HttpClientUtil.getInstance().doUpload(url,name,path);
				return ret;
			}else if("shuangpinggaopeiyi".equals(gaoPeiYiType)){
				//前端调取android双屏评价器自带高配仪
				JSONObject json11 = new JSONObject();
				json11.put("returnType", "android_gaopeiyi");
				if("true".equals(callDzzz)){
					json11.put("callDzzz", true);
					new Thread(()-> {
						JSONObject json = new JSONObject();
						JSONObject returnJson = new JSONObject();
						JSONObject jsonParams = new JSONObject();
						jsonParams.put("applicantIdNo", applicantIdNo);
						jsonParams.put("applicantName", applicantName);
						jsonParams.put("applicantType", applicantType);
						jsonParams.put("licenseName", licenseName);
						jsonParams.put("taskId", taskId);
						jsonParams.put("userId", userId);
						jsonParams.put("authCode", authCode);
						try {
							log.info("----getDzzz");
							log.info("----jsonParams1  "+jsonParams.toJSONString());
							returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPost(RECEIVEURL + "/dzzz/getDzzz", jsonParams));
							log.info("----returnJson  "+returnJson.toJSONString());
							if(returnJson.getInteger("code") == 200){
								String path1 = "http://" + JSONObject.parseObject(returnJson.getString("data")).getString("path");
								log.info("=====path1====="+path1);
								String[] strArr = path1.split("\\.");
								int subscript = strArr.length-1;
								String fileType = strArr[subscript];
								log.info("=====fileType====="+fileType);
								String dzzzFile = downloadFileAndGenerateLocalFileUrl(path1,fileType,"dzzzFile");
								log.info("=====dzzzFile====="+dzzzFile);
								json.put("returnType", "android_signing");
								json.put("dzzzState", true);
								json.put("dzzzFile", dzzzFile);
								dzzzImgBase64Json.clear();
								dzzzImgBase64Json.add(json.toJSONString());
								isget = true;
							}else{
								log.info("=====else=====");
								json.put("returnType", "android_signing");
								json.put("dzzzState", false);
								dzzzImgBase64Json.clear();
								dzzzImgBase64Json.add(json.toJSONString());
								isget = true;
							}
						} catch (Exception e) {
							e.printStackTrace();
							log.error(e.getMessage(),e);
							json.put("returnType", "android_signing");
							json.put("dzzzState", false);
							dzzzImgBase64Json.clear();
							dzzzImgBase64Json.add(json.toJSONString());
							isget = true;
						}
					}).start();
				}else{
					json11.put("callDzzz", false);
				}
				sseSend(json11.toJSONString());
				returnJson1.put("code",200);
				return returnJson1.toJSONString();
			}
		}catch (Exception e){
			e.printStackTrace();
			log.error(e.getMessage(),e);
			returnJson1.put("code",201);
			log.info(returnJson1.toJSONString());
			return returnJson1.toJSONString();
		}
		returnJson1.put("code",201);
		log.info(returnJson1.toJSONString());
		return returnJson1.toJSONString();
	}

	/**
	 * @param applicantIdNo 申请人证件号
	 * @param applicantName 申请人姓名
	 * @param applicantType 申请人类型
	 * @param licenseName 证照名称
	 * @param taskId 事项ID
	 * @param userId 用户ID
	 * @param authCode 授权码
	 * @author: 文东旭
	 * @createDate: 2021/02/06
	 * @description: 互动双屏-电子证照-人脸扫描
	 * @return
	 */
	@ApiOperation("互动双屏-电子证照-人脸扫描")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "applicantIdNo", value ="申请人证件号",dataType = "String", required = true),
			@ApiImplicitParam(name = "applicantName", value ="申请人姓名",dataType = "String", required = true),
			@ApiImplicitParam(name = "applicantType", value ="申请人类型",dataType = "String", required = true),
			@ApiImplicitParam(name = "licenseName", value ="证照名称",dataType = "String", required = true),
			@ApiImplicitParam(name = "taskId", value ="事项ID",dataType = "String", required = true),
			@ApiImplicitParam(name = "userId", value ="用户ID",dataType = "String", required = true),
			@ApiImplicitParam(name = "authCode", value ="授权码",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/faceScan")
	public String faceScan(String applicantIdNo, String applicantName, String applicantType, String licenseName, String taskId, String userId, String authCode, HttpServletResponse response) {
		log.info("--faceScan");
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject mainJson = new JSONObject();
		mainJson.put("returnType", "android_face_scan");
		mainJson.put("applicantName", applicantName);
		mainJson.put("applicantIdNo", applicantIdNo);
		sseSend(mainJson.toJSONString());
		new Thread(()->{
			JSONObject json = new JSONObject();
			JSONObject returnJson = new JSONObject();
			JSONObject jsonParams = new JSONObject();
			jsonParams.put("applicantIdNo", applicantIdNo);
			jsonParams.put("applicantName", applicantName);
			jsonParams.put("applicantType", applicantType);
			jsonParams.put("licenseName", licenseName);
			jsonParams.put("taskId", taskId);
			jsonParams.put("userId", userId);
			jsonParams.put("authCode", authCode);
			try {
				log.info("----getDzzz");
				log.info("----jsonParams2  "+jsonParams.toJSONString());
				returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPost(RECEIVEURL + "/dzzz/getDzzz", jsonParams));
				log.info("----returnJson  "+returnJson.toJSONString());
				if(returnJson.getInteger("code") == 200){
					String path = "http://" + JSONObject.parseObject(returnJson.getString("data")).getString("path");
					String[] strArr = path.split("\\.");
					int subscript = strArr.length-1;
					String fileType = strArr[subscript];
					String dzzzFile = downloadFileAndGenerateLocalFileUrl(path,fileType,"dzzzFile");
					json.put("returnType", "android_signing");
					json.put("dzzzState", true);
					json.put("dzzzFile", dzzzFile);
					dzzzImgBase64Json.clear();
					dzzzImgBase64Json.add(json.toJSONString());
					isget = true;
				}else{
					json.put("returnType", "android_signing");
					json.put("dzzzState", false);
					dzzzImgBase64Json.clear();
					dzzzImgBase64Json.add(json.toJSONString());
					isget = true;
				}
			} catch (Exception e) {
				e.printStackTrace();
				log.error(e.getMessage(),e);
				json.put("returnType", "android_signing");
				json.put("dzzzState", false);
				dzzzImgBase64Json.clear();
				dzzzImgBase64Json.add(json.toJSONString());
				isget = true;
			}
		}) .start();
		JSONObject returnJson1 = new JSONObject();
		returnJson1.put("code", 200);
		return returnJson1.toJSONString();
	}

	/**
	 * @param applicantIdNo 申请人证件号
	 * @param applicantName 申请人姓名
	 * @param applicantType 申请人类型
	 * @param licenseName 证照名称
	 * @param taskId 事项ID
	 * @param userId 用户ID
	 * @param authCode 授权码
	 * @author: 文东旭
	 * @createDate: 2021/03/06
	 * @description: 发送签字指令和电子证照（已废弃）
	 * @return
	 */
	@ApiOperation("发送签字指令和电子证照（已废弃）")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "applicantIdNo", value ="申请人证件号",dataType = "String", required = true),
			@ApiImplicitParam(name = "applicantName", value ="申请人姓名",dataType = "String", required = true),
			@ApiImplicitParam(name = "applicantType", value ="申请人类型",dataType = "String", required = true),
			@ApiImplicitParam(name = "licenseName", value ="证照名称",dataType = "String", required = true),
			@ApiImplicitParam(name = "taskId", value ="事项ID",dataType = "String", required = true),
			@ApiImplicitParam(name = "userId", value ="用户ID",dataType = "String", required = true),
			@ApiImplicitParam(name = "authCode", value ="授权码",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/sendSigning")
	public String sendSigning(String applicantIdNo, String applicantName, String applicantType, String licenseName, String taskId, String userId, String authCode, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject json = new JSONObject();
		JSONObject returnJson = new JSONObject();
		JSONObject jsonParams = new JSONObject();
		jsonParams.put("applicantIdNo", applicantIdNo);
		jsonParams.put("applicantName", applicantName);
		jsonParams.put("applicantType", applicantType);
		jsonParams.put("licenseName", licenseName);
		jsonParams.put("taskId", taskId);
		jsonParams.put("userId", userId);
		jsonParams.put("authCode", authCode);
		try {
			log.info("----getDzzz");
			log.info("----jsonParams3  "+jsonParams.toJSONString());
			returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPost(RECEIVEURL + "/dzzz/getDzzz", jsonParams));
			log.info("----returnJson"+returnJson.toJSONString());
			if(returnJson.getInteger("code") == 200){
				String path = "http://" + JSONObject.parseObject(returnJson.getString("data")).getString("path");
				log.info("----path"+path);
				String[] strArr = path.split("\\.");
				int subscript = strArr.length-1;
				String fileType = strArr[subscript];
				String dzzzFile = downloadFileAndGenerateLocalFileUrl(path,fileType,"dzzzFile");
				log.info("----dzzzFile"+dzzzFile);
				json.put("returnType", "android_signing");
				json.put("dzzzFile", dzzzFile);
				sseSend(json.toJSONString());
				returnJson.put("code", 200);
				return returnJson.toJSONString();
			}else{
				return returnJson.toJSONString();
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("code", 201);
			return jsonObject.toJSONString();
		}
	}

	/**
	 * @param file 签字水印图片(PNG格式)
	 * @author: 文东旭
	 * @createDate: 2021/06/02
	 * @description: 互动双屏-电子证照-上传签字水印图片并合并水印
	 * @return
	 */
	@ApiOperation("互动双屏-电子证照-上传签字水印图片并合并水印")
	@ApiImplicitParams({})
	@ResponseBody
	@PostMapping("/upLoadFileToLocal")
	public String upLoadFileToLocal(@RequestParam("file") MultipartFile file,HttpServletResponse response) {
		//门头沟区专用
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		JSONObject returnJson = new JSONObject();
		GraphicsUtil graphicsUtil = new GraphicsUtil();
		try {
			graphicsUtil.savePic(file,"signImg");
		}catch (IOException e) {
			e.printStackTrace();
			log.info("保存水印图片失败");
			returnJson.put("code",201);
			returnJson.put("msg","保存水印图片失败");
			return returnJson.toJSONString();
		}
		log.info("--pc_merge_watermark");
		while (true){
			if(isget){
				BufferedImage buffImg = null;
				try {
					buffImg = graphicsUtil.watermark(new File("C:\\file\\dzzzFile.jpg"), new File("C:\\file\\signImg.png"),  1.0f);
				} catch (IOException e) {
					e.printStackTrace();
					log.info("合成水印失败");
					returnJson.put("code",202);
					returnJson.put("msg","合成水印失败");
					return returnJson.toJSONString();
				}
				String path = "C:\\file\\dzzzSign.png";
				//输出水印电子证照
				graphicsUtil.generateWaterFile(buffImg, path);
				String userId = UUID.randomUUID().toString().replace("-","");
				//上传文件
				String fileStrMsg = null;
				try {
					fileStrMsg = HttpClientUtil.getInstance(charset).doUpload(RECEIVEURL+"/acceptFile/uploadFile?userId="+userId, "file", path);
				} catch (Exception e) {
					e.printStackTrace();
					log.info("上传带水印电子证照失败");
				}
				log.info("fileStrMsg"+fileStrMsg);
				//存入List等待综窗前端轮询读取数据
				dzzzImgJson.add(fileStrMsg);
				returnJson.put("code",200);
				returnJson.put("msg","合成水印成功");
				return returnJson.toJSONString();
			}
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * @author: 文东旭
	 * @createDate: 2021/06/23
	 * @description: 本地jar包获取好差评评价指标
	 * @return:
	 */
	@ApiOperation("本地jar包获取好差评评价指标")
	@ApiImplicitParams({})
	@ResponseBody
	@GetMapping("/localGetEvaluationIndexInfo")
	public String localGetEvaluationIndexInfo(HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		log.info("--localGetEvaluationIndexInfo");
		try {
			JSONObject returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doGet(URL + "/bmgTaskRecvAppraise/getEvaluationIndexInfo"));
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("code", 201);
			return jsonObject.toJSONString();
		}
	}

	/**
	 * @param promanager 专员姓名
	 * @param isConverge 是否汇聚(0:推送，9:不汇聚)
	 * @param taskName 事项名称
	 * @param department 受理部门(实施主体DEPTNAME)
	 * @param satisfaction 总体满意度，非常满意=5，满意=4，基本满意=3，不满意=2，非常不满意=1
	 * @param detail 评价详情（勾选的评价详情编号，勾选多个用逗号隔开。例：501，503，504）
	 * @param words 文字评价
	 * @param certkeygov 申请人证件号码
	 * @param userName 申请人名称
	 * @param telPhone 申请人手机号
	 * @author: 文东旭
	 * @createDate: 2021/06/23
	 * @description: 本地jar包好差评-群众pad评价提交接口
	 * @return:
	 */
	@ApiOperation("本地jar包好差评-群众pad评价提交接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "promanager", value ="专员姓名",dataType = "String", required = true),
			@ApiImplicitParam(name = "isConverge", value ="是否汇聚(0:推送，9:不汇聚)",dataType = "String", required = true),
			@ApiImplicitParam(name = "taskName", value ="事项名称",dataType = "String", required = true),
			@ApiImplicitParam(name = "department", value ="受理部门(实施主体DEPTNAME)",dataType = "String", required = true),
			@ApiImplicitParam(name = "satisfaction", value ="总体满意度，非常满意=5，满意=4，基本满意=3，不满意=2，非常不满意=1",dataType = "String", required = true),
			@ApiImplicitParam(name = "detail", value ="评价详情（勾选的评价详情编号，勾选多个用逗号隔开。例：501，503，504）",dataType = "String", required = true),
			@ApiImplicitParam(name = "words", value ="文字评价",dataType = "String", required = true),
			@ApiImplicitParam(name = "certkeygov", value ="申请人证件号码",dataType = "String", required = true),
			@ApiImplicitParam(name = "userName", value ="申请人名称",dataType = "String", required = true),
			@ApiImplicitParam(name = "telPhone", value ="申请人手机号",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/localBusUserEvaluationMassesPad")
	public String localBusUserEvaluationMassesPad(String promanager, String isConverge, String taskName,String department,String satisfaction,String detail,String words,String certkeygov,String userName,String telPhone,HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		log.info("--localBusUserEvaluationMassesPad");
		try {
			JSONObject paramsJson = new JSONObject();
			paramsJson.put("promanager",promanager);
			paramsJson.put("isConverge",isConverge);
			paramsJson.put("taskName",taskName);
			paramsJson.put("department",department);
			paramsJson.put("satisfaction",Integer.parseInt(satisfaction));
			paramsJson.put("detail",detail);
			paramsJson.put("words",words);
			paramsJson.put("certkeygov",certkeygov);
			paramsJson.put("userName",userName);
			paramsJson.put("telPhone",telPhone);
			System.out.println(paramsJson.toJSONString());
			JSONObject returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPostJson(URL + "/sseController/busUserEvaluationMassesPad",paramsJson));
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("code", 201);
			return jsonObject.toJSONString();
		}
	}

	/**
	 * @param jsonParams 伟仕(第三方公司)提交的好差评数据
	 * @author: 文东旭
	 * @createDate: 2021/07/19
	 * @description: 社保大厅对接好差评接口
	 * @return: {"code": 0, "msg": ""} code=0成功,code=1失败   msg：失败原因   第三方要求格式
	 */
	@ApiOperation("社保大厅对接好差评接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "jsonParams", value ="伟仕(第三方公司)提交的好差评数据",dataType = "String", required = true)
	})
	@ResponseBody
	@PostMapping("/localSocialSecurityHallHCP")
	public String localSocialSecurityHallHCP(@RequestBody Map jsonParams, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		log.info("--localSocialSecurityHallHCP");
		JSONObject jsonObject = new JSONObject();
		try {
			socialSecurityHallJson = new JSONObject(jsonParams);
			JSONObject json = new JSONObject();
			json.put("returnType", "android_social_security_hall_hcp");
			JSONObject evaluationIndexInfoJson = JSONObject.parseObject(HttpClientUtil.getInstance().doGet(URL + "/bmgTaskRecvAppraise/getEvaluationIndexInfo"));
			if(evaluationIndexInfoJson.getInteger("code") == 200){
				json.put("evaluationIndexInfo", evaluationIndexInfoJson.get("EvaluationIndexInfo"));
			}else{
				new Exception();
			}
			sseSend(json.toJSONString());
			jsonObject.put("code", 0);
			jsonObject.put("msg", "邀请评价成功");
			return jsonObject.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			jsonObject.put("code", 1);
			jsonObject.put("msg", "邀请评价失败");
			return jsonObject.toJSONString();
		}
	}

	/**
	 * @param isConverge 是否汇聚(0:推送，9:不汇聚)
	 * @param satisfaction 总体满意度，非常满意=5，满意=4，基本满意=3，不满意=2，非常不满意=1
	 * @param detail 评价详情（勾选的评价详情编号，勾选多个用逗号隔开。例：501，503，504）
	 * @param words 文字评价
	 * @author: 文东旭
	 * @createDate: 2021/07/19
	 * @description: 社保大厅Pad提交好差评接口
	 * @return:
	 */
	@ApiOperation("社保大厅Pad提交好差评接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "isConverge", value ="是否汇聚(0:推送，9:不汇聚)",dataType = "String", required = true),
			@ApiImplicitParam(name = "satisfaction", value ="总体满意度，非常满意=5，满意=4，基本满意=3，不满意=2，非常不满意=1",dataType = "String", required = true),
			@ApiImplicitParam(name = "detail", value ="评价详情（勾选的评价详情编号，勾选多个用逗号隔开。例：501，503，504）",dataType = "String", required = true),
			@ApiImplicitParam(name = "words", value ="文字评价",dataType = "String", required = true)
	})
	@ResponseBody
	@GetMapping("/localSocialSecurityHallHCPPadSubmit")
	public String localSocialSecurityHallHCPPadSubmit(String isConverge, String satisfaction, String detail, String words, HttpServletResponse response) {
		//设置响应头
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setStatus(200);
		response.setHeader("connection", "close");
		log.info("--localSocialSecurityHallHCPPadSubmit");
		try {
			JSONObject paramsJson = new JSONObject();
			JSONObject evaluationJson = new JSONObject();
			evaluationJson.put("isConverge",isConverge);
			evaluationJson.put("satisfaction",Integer.parseInt(satisfaction));
			evaluationJson.put("detail",detail);
			evaluationJson.put("words",words);
			paramsJson.put("evaluationJson",evaluationJson);
			paramsJson.put("socialSecurityHallJson",socialSecurityHallJson);
			log.info(paramsJson.toJSONString());
			JSONObject returnJson = JSONObject.parseObject(HttpClientUtil.getInstance(charset).doPostJson(URL + "/sseController/socialSecurityBureau",paramsJson));
			return returnJson.toJSONString();
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(),e);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("code", 201);
			return jsonObject.toJSONString();
		}
	}


}
